package Gather.MapExercise.MapDome;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

/**
 * ClassName:MapText005
 * Package:Gather.MapExercise
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/20-19:06
 * @Version:v1.0
 */
public class MapText005 {
    /*Lambda表达式遍历Map集合*/
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        //添加元素
        //键：人物的名字
        //值：名人名言
        map.put("鲁迅","这句话是我说的");
        map.put("曹操","不可能绝对不可能");
        map.put("刘备","接着奏乐接着舞");
        map.put("柯镇恶","看我眼色行事");

        //利用Lambda表达式进行遍历
        map.forEach(new BiConsumer<String, String>() {
            @Override
            public void accept(String key, String value) {
                System.out.println(key+"="+value);
            }
        });

        System.out.println("---------------------------");
        //简写Lambda表达式
        map.forEach((key,value)-> System.out.println(key+"="+value));
    }
}
